This invention is generally related to computers and computer software, and more specifically is related to improving the handling of sleeping tasks waiting on the I/O operations of other tasks.
Computer technology continues to be improved for handling more useful and complex functions associated with specific applications. Despite the continual advances in the speed and power of computers, however, these applications of computer technology continue to demand even greater computing power. For this reason, an ever-present need exists for improving the performance of the computer software that controls how a computer operates.
Generally, the software that controls how the computer operates, in its most basic form, is referred to as the operating system of the computer. The operating system is essentially a set of software programs that manages the various hardware and software resources of the computer and handles the computer""s interaction with users. For example, it is the operating system that creates the computer""s prompts and screens on the monitor to interface with a user and that runs the computer""s programs for the user. Furthermore, the operating system will allow a computer to interface with its hardware resources, such as a printer or a disk drive, or will allow a user to run other higher level software applications on the computer such as Microsoft""s WINDOWS program. The operating system, therefore, must be able to complete a large number of different functions to ensure that the computer, including its accessible hardware and software resources, functions properly and at a sufficient speed for the user.
Within the operating system of a computer, the various internal functions which are handled are referred to as xe2x80x9ctasks.xe2x80x9d These various tasks may be thought of, in the traditional sense, as jobs that the computer must do when it is properly running programs for a user. A related series of such tasks is referred to as a thread. For example, a task might involve updating the contents of a file or writing a file to a storage device, such as a disk drive. A thread, on the other hand, may consist of a series of such tasks including updating the contents of a file, and then, when the file is updated, writing the file to the disk.
Within an operating system, the tasks will generally be taking place simultaneously for efficient operation of the computer, that is, two or more different tasks or threads will be running at the same time. The various tasks will usually continue to completion unhindered and will then be repeated as necessary depending upon the applications being run on the computer by a user. In such a scenario, one task or thread would not interfere with or hinder another task or thread.
However, for certain software applications, it may be necessary for certain tasks to wait until other tasks have been completed. This is usually the case where tasks will need to access a hardware resource or device, such as a disk drive and will require other tasks to wait until such access has been competed. That is, certain related tasks or threads, once they have executed, may have to wait until another group of tasks or threads completes their interaction with a hardware device before they resume and/or repeat.
To that end, a particular software application will require a second group of tasks to wait until the hardware access of a first group of tasks is complete, and then the second group of tasks will be free to resume. Task access to a hardware resource by the operating system is generally referred to as an INPUT/OUTPUT operation or I/O operation. Not all tasks will require an I/O operation, and therefore many tasks will be completed unhindered by ongoing I/O operations by other tasks. However, as noted, a second group of tasks may require completion of all the I/O operations of a first group of tasks before the second group resumes. That is, the second group of tasks xe2x80x9cwaitsxe2x80x9d on the first group to complete its I/O operations.
To effect such waiting between tasks, the software of the computer will effectively block the progression of the second group of tasks until the I/O operations of the first group of tasks are initiated and completed. One technique for making the second task group wait is to use a software block object for the task group. The block object is a software object that is associated with waiting tasks and that will effectively prevent the second task group from proceeding until it is removed. The removal of the block object with respect to the waiting tasks is referred to as xe2x80x9cunblockingxe2x80x9d. The waiting tasks are referred to as being xe2x80x9casleepxe2x80x9d. When the block object is unblocked, the sleeping tasks are xe2x80x9cawakenedxe2x80x9d and will proceed to execute.
Putting tasks to sleep to await completion of the I/O operations of other tasks is a known method of controlling the overall operation of a computer software program when multi-tasks or multi-threads are utilized in the program. For example, within programs running on the IBM AS400 operating system, a software object referred to as the AsyncTracker will use block objects to control the start of tasks within a multi-task environment. With AsyncTracker, a task is put to sleep by blocking it with a block object. When the I/O operations are complete, the task is awaken by unblocking the block object. Problems will sometimes occur, however, when a task or thread is waiting for completion of an I/O operation, and completion of that I/O operation never occurs. The task may then remain asleep indefinitely, which is an undesirable condition. For example, such indefinite waiting may occur when the first task or thread is unreliable and does not initiate the I/O operations. The block objects will remain in place and the tasks will not awaken. This may cause problems within the program because the waiting tasks are not executed.
Therefore, a need exists to be able to address sleeping tasks and threads waiting for the completion of I/O operations related to an unreliable task or tasks. Specifically a need exists to awaken sleeping tasks and threads when the I/O operation they are waiting for is not in progress.
The invention addresses the above-referenced problems and other problems associated with the prior art of the computer system, program product, and method, which improves the handling of sleeping tasks which are waiting for completion of I/O operations of other tasks. More specifically, a second task, or a set of second tasks, which are to await the completion of the I/O operations of a first task, or of a set of first tasks, is determined and the second task(s) are put to sleep. A timer is then created and is associated with the second task(s). The timer expires when a predetermined wait interval is exceeded. When the timer expires, the sleeping second task(s) are awakened, regardless of the completion of the I/O operations of the first task(s). Thereby, sleeping task(s) are generally prevented from waiting indefinitely for the I/O operations of other task(s) which may be unreliable. More specifically, a block object is created and the second task(s) are put to sleep by blocking those task(s) with the block object. The block object is configured so that the second task(s) awaken when the block object is unblocked. The block object is associated with the timer, and when the timer expires, the block object is unblocked to thereby awaken the sleeping second task(s). In accordance with one aspect of the present invention, when a set of tasks is put to sleep to await a timer, one of the tasks may be awakened while other of the tasks remain sleep. The awoken tasks will then initiate and complete the necessary I/O operations and the remaining sleeping tasks will awaken when those I/O operations are complete.
In accordance with another aspect of the present invention, the timer is created when the last I/O operation of the task upon which the other tasks are waiting has not been commenced. Conversely, the created timer will then be cancelled should the last I/O operation of the waited upon task commence. Further, the sleeping second task(s) will be awakened when the I/O operations of the first task(s) are completed, independent of the timer expiration. Therefore, while the timer is created in accordance with the present invention to generally prevent indefinite waiting of a set of tasks upon the I/O operations of another task, upon completion of those I/O operations, the timer will generally have no effect and the sleeping tasks will be awoken and will proceed in the usual manner.
In accordance with another aspect of the present invention, the outstanding I/O operations of first task(s) to be completed are monitored. The commencement of the last I/O operation of the outstanding I/O operations is also monitored. By monitoring those two conditions, the completion of the first task(s) I/O operations is determined, and if all of the I/O operations are completed and the last I/O operation has commenced, then the sleeping task(s) are awoken. These features and other features of the invention are discussed in greater detail below in the Detailed Description of the Invention which makes reference to the drawings to illustrate one or more embodiments of the invention.